package io;

import java.io.*;

/**
 * @author IT枫斗者
 * @ClassName ConversionStreamDemo.java
 * @From www.javatiaozao.com
 * @Description TODO
 */
public class ConversionStreamDemo {
    public static void main(String[] args) throws IOException {
        //写的步骤
//        OutputStreamWriter(OutputStream out,String charset)
//        使用指定的字符编码创建 OutputStreamWriter对象
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("myStream/osw.txt"), "GBK");
        //现在对我们指定的文件中写入字符
        osw.write("我是IT枫斗者，我爱中国！");
        osw.close();

//        InputStreamReader(InputStream in,Stringchatset)
//        使用指定的字符编码创建 InputStreamReader对象
        //读的步骤
        InputStreamReader isr = new InputStreamReader(new FileInputStream("myStream/osw.txt"), "GBK");
        int chs;
        while ((chs = isr.read()) != -1){
            System.out.println((char) chs);
        }
        isr.close();
    }
}
